<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script src="ajax.js" charset="utf-8"></script>
    <script type="text/javascript">
      window.onload=function (){
        var oBtn1=document.getElementById('btn1');
        var oBtn2=document.getElementById('btn2');
        var oUser=document.getElementById('user');
        var oPass=document.getElementById('pass');

        oBtn1.onclick=function (){
          ajax({
            url: 'http://localhost:8080/register',
            data:{user: oUser.value, pass: oPass.value},
            type:'get',
            success:function (str){
              var json=eval('('+str+')');

              if(json.ok){
                alert('注册成功');
              }else{
                alert('注册失败：'+json.msg);
              }
            },
            error: function (){
              alert('通信失败');
            }
          });
        }
        oBtn2.onclick=function (){
          ajax({
            url: 'http://localhost:8080/login',
            data:{user: oUser.value, pass: oPass.value},
            type:'get',
            success:function (str){
              var json=eval('('+str+')');

              if(json.ok){
                alert('登录成功');
              }else{
                alert('登录失败：'+json.msg);
              }
            },
            error: function (){
              alert('通信失败');
            }
          });
        }
      };
    </script>
  </head>
  <body>
    用户：<input type="text" id="user" /><br>
    密码：<input type="password" id="pass" /><br>
    <input type="button" value="注册" id="btn1">
    <input type="button" value="登录" id="btn2">
  </body>
</html>
